<template>
  <footer class="footer" v-if="list.length>0">
      <span class="todo-count"><strong>{{leftCount}}</strong>剩余</span>
      <ul class="filters">
        <li>
          <a :class="{selected:type === 'all'}" @click.prevent="filter('all')" href="#/">全部</a>
        </li>
        <li>
          <a :class="{selected:type === 'active'}" href="#/active" @click.prevent="filter('active')">进行中</a>
        </li>
        <li>
          <a :class="{selected:type === 'completed'}" href="#/completed" @click.prevent="filter('completed')">已完成</a>
        </li>
      </ul>
      <button class="clear-completed" v-show="isShowClear" @click="clear">清除已完成</button>
    </footer>
</template>

<script>
export default {
  props: {
    list: {
      type: Array,
      required: true
    },
    type: String
  },
  data() {
    return {
      
    }
  },
  computed: {
    // 未完成任务数
    leftCount () {
      return this.list.filter(item => item.isDone === false).length
    },
    // 如果list数组中有一个完成任务的就显示
    isShowClear() {
      // some 一真即真  every 一假即假
      return this.list.some(item => item.isDone)
    }
  },
  methods: {
    clear() {
      this.$emit('clear')
    },
    filter(type) {
      // this.type = type
      this.$emit('changeType', type)
    }
  }
}
</script>

<style>

</style>